<?php
//用户的日志记录
class MemberlogModel extends CommonModel {
	public function __construct(){
		parent::__construct();
	}
	//获取日志数据
	public function queryMemberLog($p , $per_page = 100 , $where = array() ){
		if($p <=0 ){
			$p = 1 ;
		}
		$getwhere = " where 1 = 1 " ;
		if(isset($where['username']) &&  $where['username'] ){
			$getwhere.=" AND b.username = '{$where['username']}' ";
		}
		if(isset($where['phone']) &&  $where['phone'] ){
			$getwhere.=" AND b.phone = '{$where['phone']}' ";
		}
		if(isset($where['uid']) &&  $where['uid'] ){
			$getwhere.=" AND a.uid = '{$where['uid']}' ";
		}
		
		//echo $getwhere ;
		import('Library.Page' , APP_PATH);
		$limit = ($p-1)*$per_page;
		$limit.=",{$per_page}";
		$where = '1= 1 ';
		$sql_count = "select count(*) as c from ".C("DB_PREFIX")."member_log as a left join ".C("DB_PREFIX")."member as b on a.uid = b.uid {$getwhere}" ;
		$count_data = M()->query($sql_count);
		$total = $count_data[0]['c'];
	
		$page = new Page($total,$per_page);
		$page_string =  $page->show();
	
		$sql = "select a.*  , b.username , b.phone   from ".C("DB_PREFIX")."member_log as a left join ".C("DB_PREFIX")."member as b on a.uid = b.uid {$getwhere} order by a.id desc  limit {$limit}" ;
		//echo $sql;
		$list = M()->query($sql);
	
		if($list){
			foreach($list AS $k1 => $v1 ){
				$list[$k1]['add_time'] = isset($v1['add_time'])?date("Y-m-d H:i",$v1['add_time']):'' ;		
			}
		}
		return array('list'=>$list , 'page_string'=>$page_string);
	}
	
	
}
